package com.pactera.android.activity;

import com.pactera.android.R;
import com.pactera.android.application.PacteraApplication;
import com.pactera.android.service.NotificationService;

import android.app.ActivityGroup;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;


@SuppressWarnings("deprecation")
public class FrameActivity extends ActivityGroup  {
	
	static final String TAG = "FrameActivity";
	
    private TabHost tabHost;
    
    private PacteraApplication app;

    @Override   
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        app = (PacteraApplication)getApplication();
        setContentView(R.layout.frame_activity);
        
        Resources res = getResources();
        tabHost = (TabHost)findViewById(R.id.tabhost);
        
        tabHost.setup(getLocalActivityManager());
     
        
        TabHost.TabSpec spec;  
        Intent intent;   
        intent = new Intent().setClass(this, ContactListActivity.class);            
        spec = tabHost.newTabSpec("Home").setIndicator("Home", res.getDrawable(R.drawable.icon_home_config))
        		.setContent(intent);  
        tabHost.addTab(spec);
        
        intent = new Intent().setClass(this, ContactListWebviewActivity.class);
        spec = tabHost.newTabSpec("WebView").setIndicator("Profile", res.getDrawable(R.drawable.icon_profile_config))  
                .setContent(intent);  
        tabHost.addTab(spec); 
        
        intent = new Intent().setClass(this, MessageActivity.class);
        spec = tabHost.newTabSpec("Message").setIndicator("Message", res.getDrawable(R.drawable.icon_message_config))  
                .setContent(intent);  
        tabHost.addTab(spec); 
        
        intent = new Intent().setClass(this, MoreActivity.class);
        spec = tabHost.newTabSpec("More").setIndicator("More", res.getDrawable(R.drawable.icon_more_config))  
                .setContent(intent);  
        tabHost.addTab(spec); 

    }


    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.base_menu, menu);
		return true;
	}

	/* (non-Javadoc)
	 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		 switch (item.getItemId()) {
	        case R.id.refresh:	
	        	
	            return true;
	        case R.id.quit:
	        	Intent intent = new Intent(Intent.ACTION_MAIN);
	        	intent.addCategory(Intent.CATEGORY_HOME);
	        	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	        	startActivity(intent);
	        	return true;
	        	
	        case R.id.toggleService:
	        	if (app.isNotificationServiceRunning()) {
	        		stopService(new Intent(this, NotificationService.class));
	        	} else {
	        		startService(new Intent(this, NotificationService.class));
	        	}
	        	return true;
	        	
	        	default: 
	        		super.onOptionsItemSelected(item);
	        	return true;
		 }	 
	}


	
    
	

}
